/*
PearReview - The peer review assistant.
Copyright (C) 2009  Dimitrij Pankratz, Anton Musichin
http://www.pearreview.com, info@pearreview.com

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

package com.pearreview.ui.table;

import java.awt.Component;
import java.util.Map;

import javax.swing.JTable;

import com.pearreview.util.review.Severity;

public class SeverityMapTableCellRenderer 
		extends SeverityTableCellRenderer {
	private static final long serialVersionUID = 2592411193708268899L;
	private Map<Severity, String> severityMap;
	public SeverityMapTableCellRenderer() {
		
	}
	public SeverityMapTableCellRenderer(Map<Severity, String> severityMap) {
		this.severityMap = severityMap;
	}
	public void setSeverityMap(Map<Severity, String> severitySet) {
		this.severityMap = severitySet;
	}
	public Map<Severity, String> getSeverityMap() {
		return severityMap;
	}
	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		
		super.getTableCellRendererComponent(table, 
				value, 
				isSelected, 
				hasFocus, 
				row, 
				column);
		
		if(value instanceof Severity) {
			Severity severity = (Severity)value;
			if(severityMap == null || !severityMap.containsKey(severity)) {
				setText(severity.getName());
			} else {
				setText(severityMap.get(severity));
			}
		}
		return this;
	}
}